package cluster

import (
	"go-redis/interface/resp"
	"go-redis/resp/reply"
)

// flush命令的处理函数
func flushdbFunc(cluster *ClusterDatabase, c resp.Connection, cmdArgs [][]byte) resp.Reply {
	replies := cluster.broadcast(c, cmdArgs)
	var errReply reply.ErrorReply
	for _, v := range replies {
		if reply.IsErrorReply(v) {
			errReply = v.(reply.ErrorReply)
			break
		}
		_, ok := v.(*reply.OkReply)
		if !ok {
			errReply = reply.MakeErrReply("error")
		}
	}
	if errReply != nil {
		return reply.MakeErrReply("error occurs: " + errReply.Error())
	}
	return reply.MakeOkReply()
}
